import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:xvideos/hj_page/community_business/publish_page/publish_controller.dart';
import 'package:xvideos/hj_page/community_business/publish_page/publish_rule_page.dart';
import 'package:xvideos/hj_page/community_business/publish_page/widget/publish_imply_info_widget.dart';
import 'package:xvideos/hj_page/community_business/publish_page/widget/publish_widget.dart';
import 'package:xvideos/hj_utils/widget_utils.dart';

import '../../../alert_business/video/vip_acg_dailog.dart';
import '../widget/post_rule_dialog.dart';
import 'chose_tag_page.dart';

enum PublishType {
  homeImg(RuleType.home, ChoseTopicEntry.home),
  homeImgText(RuleType.home, ChoseTopicEntry.home),
  homeVideo(RuleType.home, ChoseTopicEntry.home),
  squireImgText(RuleType.squire, ChoseTopicEntry.squire),
  squireVideo(RuleType.squire, ChoseTopicEntry.squire);

  final RuleType rule;
  final ChoseTopicEntry tag;

  const PublishType(this.rule, this.tag);
}

extension PublishMore on PublishType {
  String publishTitle() {
    if (this == PublishType.homeImg) return '发布图片';
    if (this == PublishType.homeImgText) return '发布图文';
    if (this == PublishType.homeVideo) return '发布视频';
    if (this == PublishType.squireImgText) return '发布帖子';
    return '发布帖子';
  }

  List<Widget> getChildren() {
    if (this == PublishType.homeImg) {
      return [
        TopicWidget(),
        InputTitleWidget(),
        ChoseImageWidget(highlightText: '添加图集'),
        // SettingGoldWidget(),
        // PublishImplyInfoWidget(),
      ];
    }
    if (this == PublishType.homeImgText) {
      return [
        TopicWidget(),
        InputTitleWidget(),
        InputDescribeWidget(),
        ChoseImageWidget(highlightText: '添加图集'),
        // SettingGoldWidget(),
        // PublishImplyInfoWidget(),
      ];
    }
    if (this == PublishType.homeVideo) {
      return [
        TopicWidget(),
        InputTitleWidget(),
        InputDescribeWidget(),
        SettingGoldWidget(),
        ChoseVideoWidget(),
        ChoseImageWidget(
          hint: '「默认第一张为封面」图片数量最多9张哦～',
          highlightText: '「默认第一张为封面」',
          highlightTextSize: 12.sp,
          highlightTextColor: Color(0xffB40400),
        ),
        // PublishImplyInfoWidget(isVideoStyle: true),
      ];
    }
    if (this == PublishType.squireImgText) {
      return [
        TopicWidget(),
        InputDescribeWidget(),
        ChoseImageWidget(
          hint: '第一张图集默认为封面',
        ),
      ];
    }
    return [TopicWidget(), InputDescribeWidget(), ChoseVideoWidget()];
  }
}

class PublishPage extends StatelessWidget {
  static const routeName = '/community/publish';

  PublishPage({super.key});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {},
      child: GetBuilder(
        init: PublishController(),
        builder: (_) {
          return Scaffold(
            appBar: AppBar(
              centerTitle: true,
              title: Text(_.type.publishTitle()),
              actions: [
                TextButton(
                    onPressed: () async {
                      await Get.dialog(const PostRuleDialog());
                    }, child: Text(
                  "规则",style: TextStyle(color: Color(0x73FFFFFF)),
                )),
                18.w.sizeBoxW,
              ],
            ),
            body: Container(
              margin: EdgeInsets.symmetric(horizontal: 18.w),
              width: double.infinity,
              child: SafeArea(
                child: Column(
                  children: [
                    Expanded(child: SingleChildScrollView(
                      child: Container(
                        padding: EdgeInsets.only(bottom: 24),
                        child:Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: _.type.getChildren(),
                        ),
                      ),
                    )),
                    GestureDetector(
                      child: Container(
                        margin: EdgeInsets.symmetric(horizontal: 20,vertical: 20.h),
                        padding: EdgeInsets.symmetric(horizontal: 6.w, vertical: 10.h),
                        alignment: Alignment.center,
                        width: double.infinity,
                        decoration: BoxDecoration(
                            color: Color(0xFFE1351F),
                            borderRadius: BorderRadius.circular(10)
                        ),
                        child: Text(
                          '确定发布',
                          style: TextStyle(color: Colors.white, fontSize: 16, height: 27 / 14),
                        ),
                      ),
                      onTap: () => _.publish(),
                    )
                  ],
                ),
              ),
            ),
          );
        },
      ),
    );
  }

  Widget publishBtn(){
    return GetBuilder(
      init: PublishController(),
      builder: (_) {
        return GestureDetector(
          child: Container(
            padding: EdgeInsets.symmetric(horizontal: 14.w, vertical: 2.h),
            // alignment: Alignment.center,
            decoration: BoxDecoration(
                gradient: LinearGradient(
                    colors: [Color(0xff439FFF), Color(0xff0865FD)], begin: Alignment.centerLeft, end: Alignment.centerRight),
                borderRadius: BorderRadius.circular(40)),
            child: Text(
              '发布',
              style: TextStyle(color: Colors.white, fontSize: 14, height: 27 / 14),
            ),
          ),
          onTap: () => _.publish(),
        );
      },
    );
  }
}
